#ifndef _MW_SESSION_H
#define _MW_SESSION_H


/*

*/


typedef struct mw_session {
  MwObject mwobject;

} MwSession;



typedef struct mw_session_class {
  MwObjectClass mwobjectclass;

} MwSessionClass;



MwSession *mw_session_new();


/** These functions, together with the "write" signal, are used to get
    data from a socket and feed it into the session, and vise-verse.
    
    @section Basic Input Output
    @{
*/


/** Feed a buffer of data to the session's message parser. As each
    message is completed, the session will handle it in order before
    continuing with parsing the next message. */
void mw_session_feed(MwSession *session, const guchar *buf, gsize len);


/** count of pending outgoing writes */
guint mw_session_pending(MwSession *session);


/** flush msgcount outgoing writes. This will cause the write signal
    to be emitted once for each outgoing message, up to msgcount
    times. If any of the write handlers return a value greater than
    zero, any further writes will be considered defered and will not
    trigger the write signal until the next call to flush. If any of
    the write handlers return a value less than zero, the write is
    considered to have failed, and the session will stop with an error
    code. Returns count of messages actually written. */
guint mw_session_flush(MwSession *session, guint msgcount);


/** queues a message to be sent */
void mw_session_send_message(MwSession *session, const MwMessage *message);


/** queues a keepalive to be sent. If immediate is TRUE, then the
    keepalive will be placed at the front of the queue, and flush will
    be called to send it. Otherwise, the keepalive will be placed at
    the end of the session message queue */
void mw_session_send_keepalive(MwSession *session, gboolean immediate);


/** @} */



#endif _MW_SESSION_H
